package logic

import (
	"context"
	"fmt"
	"gorm.io/gorm"
	"src/models/mysql"

	"src/internal/svc"
	"src/src"

	"github.com/zeromicro/go-zero/core/logx"
)

type RegisterLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewRegisterLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RegisterLogic {
	return &RegisterLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *RegisterLogic) Register(in *src.RegisterRequest) (*src.RegisterResponse, error) {
	// todo: add your logic here and delete this line

	register := mysql.Account{
		Model:    gorm.Model{},
		Tel:      in.Tel,
		Password: in.Password,
		Status:   in.Status,
	}
	err := mysql.DB.Debug().Model(&register).Create(&register).Error
	if err != nil {
		return nil, fmt.Errorf("注册失败")
	}
	return &src.RegisterResponse{Id: int64(register.ID)}, nil
}
